<!DOCTYPE html>
<html lang="en">

<head>
    <meta charset="UTF-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Document</title>
</head>
<style>
    .content {
        margin: 0 auto;
        width: 960px;
    }
    input{
        width: 920px;
        height: 30px;
    }
    table{
        width: 930px;
        text-align: center;
    }
    .mar{
        margin: 20px 0 20px 0;
        cursor: pointer;
        background-color: salmon;
        width: 65px;
        height: 20px;
    }
    .ma{
        margin: 10px 0 0 0;
        cursor: pointer;
        background-color: green;
        width: 65px;
        height: 20px;
    }
    .red{
       color:red;
    }
</style>

<body>
    <div id="app" class="content">
        <p>序号:</p>
        <input type="text" name="" id="" v-model="newall.selectall">
        <p>角色名:</p>
        <input type="text" name="" id="" v-model="newall.rolename">
        <p>系列:</p>
        <input type="text" name="" id="" v-model="newall.series">
        <p>擅长:</p>
        <input type="text" name="" id="" v-model="newall.goodat">

        <div class="mar" v-if="isboll" @click="addpersen">创建角色</div>
        <div class="red" v-else @click="addpersave">保存修改</div>

        <table border="1">
            <tr>
                <th>序号</th>
                <th>角色名</th>
                <th>系列</th>
                <th>擅长</th>
                <th>操作</th>
            </tr>
            <tr v-for="(item,index) in all">
                <td>{{item.selectall}}</td>
                <td>{{item.rolename}}</td>
                <td>{{item.series}}</td>
                <td>{{item.goodat}}</td>
                <td><button @click="xiugaibtn">修改</button>
                    <button @click=" del(index)">删除</button>
                </td>
        </table>
        <button class="ma" @click="up">升序</button>
        <button class="ma" @click="down">降序</button>
    </div>
    <script src="../js/vue.js"></script>
    <script>
        const app = new Vue({
            el: "#app",
            data: {
                all: [
                    { "selectall":" 12", "rolename": "花仙兽", "series": "水", "goodat": "攻击", "operation": "" },
                    { "selectall": "6", "rolename": "祖盾兽", "series": "火", "goodat": "防御", "operation": "" },
                    { "selectall": "4", "rolename": "钢铁侠", "series": "地", "goodat": "攻击", "operation": "" },
                ],
                isboll:true,
                newall:{ "selectall": "", "rolename": "", "series": "", "goodat": ""}
            },
            methods:{
                del(index){
                     this.all.splice(index, 1)
                },
                addpersen(){
                    this.all.push(this.newall)
                   
                },
                up(){
                    this.all.sort(function(a,b){
                        return a.selectall-b.selectall
                    })
                },
                down(){
                     this.all.sort(function (a, b) {
                        return b.selectall - a.selectall
                    })
                },
                addpersave(){
                     this.isboll = !this.isboll
                },
                xiugaibtn(){
                     this.isboll = !this.isboll
                }
            }
        })
    </script>
</body>

</html>